Write-Host "-------------------------------------------------"
Write-Host "HARLIANE PACKAGER"
Write-Host "-------------------------------------------------"

$CVSROOT=":pserver:anonymous@azrael:/CVSROOT"
$CVSHOST="herve@azrael"

$DISTRIB="C:\dev\php"

$PUTTYLINK="c:\homeware\putty\PLINK.EXE"
$PUTTYSCP="c:\homeware\putty\PSCP.EXE"

# ===========================================================
# MAIN 
$version="";
$tag="";

$i = 0;
while ($i -lt $args.Length)
{
    $cm = $args[$i].ToLower();

    if ($cm -eq "-version" -or $cm -eq "-v")
    {
        $version = $args[$i+1];
        $i = $i+2;
    }
    elseif ($cm -eq "-tag" -or $cm -eq "-t")
    {
        $tag = $args[$i+1].ToUpper();
        $i = $i+2;
    }
    else
    {
        Write-Host "Unknown parameter $cm"
        $i++;
    }
}


if ($tag -eq "")
{
    $tag = "HARLIANE_" + $version;
    $tag = $tag -replace("\.", "-");
}

Write-Host "Version: $version"
Write-Host "Tag    : $tag"

$CVS_EXPORT_CMD="rm -rf harliane-$version ; cvs -d '$CVSROOT' export -d harliane-$version -r $tag harliane > harliane-$version.log 2>&1 "
$CVS_SRC_DIR=$CVSHOST + ":harliane-$version"
$CVS_INS_DIR=$DISTRIB + "\harliane-$version"

Write-Host "$CVS_EXPORT_CMD"
& $PUTTYLINK $CVSHOST, $CVS_EXPORT_CMD
if ($?)
{
	Write-Host "Package harliane-$version extacted from CVS"
	if (Test-Path $CVS_INS_DIR)
	{
		Remove-Item $CVS_INS_DIR -recurse
	}
	Write-Host "Deploying harliane $version from $CVS_SRC_DIR to $CVS_INS_DIR"
	& $PUTTYSCP -r, $CVS_SRC_DIR, $CVS_INS_DIR
	
}else{
	Write-Host "Unable to extract package harliane-$version from CVS"
	& $PUTTYLINK $CVSHOST, "cat harliane-$version.log"
}


